<template>
	<view>
		<u-navbar title="身份验证" @rightClick="rightClick" :placeholder="true" :autoBack="true"></u-navbar>
		<view class="page">
			<view class="tips">
				请输入验证码
			</view>
			<view class="tips1">
				验证码已发送至{{utils.encryptionMobile(phone)}}
			</view>
			<view class="code">
				<u-code-input v-model="code" @finish="finish" fontSize="25" size="45" space="15" mode="line"></u-code-input>
			</view>
			<view class="countdown" v-if="interValTime!=0">
				{{interValTime}}秒后重新获取验证码
			</view>
			<view class="btn" v-if="interValTime==0">
				<u-button color="#28AC3E" text="重新发送验证码" @click="sendCode"></u-button>
			</view>
			<view class="bottom-tips">
				若原手机号已停用，请联系4S店管理员
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: '',
				interValTime: 60,
				Info: this.$store.state.Info,
				phone: uni.getStorageSync("urlParams").mobile,
				type: 0,
			}
		},
		onLoad(options) {
			this.type = options.type;
			let interVal = setInterval(() => {
				this.interValTime--;
				if (this.interValTime == 0) {
					clearInterval(interVal);
				}
			}, 1000)
			// this.phone = this.utils.encryptionMobile(this.Info.phone);
			// this.phone = "15955587013"
			// this.phone = uni.getStorageSync("Info").phone;
		},
		methods: {
			rightClick() {

			},
			//重新发送验证码
			sendCode() {
				this.interValTime = 60
				uni.showLoading({
					title: "正在获取验证码",
					mask: true
				})
				this.api.sendMsg({
					mobile: this.phone,
					id: uni.getStorageSync("Info").id,
					type: 11
				}).then(res => {
					uni.hideLoading();
					uni.$u.toast("验证码发送成功");
					let interVal = setInterval(() => {
						this.interValTime--;
						if (this.interValTime == 0) {
							clearInterval(interVal);
						}
					}, 1000)
				})

			},
			finish(e) {
				this.api.checkMobile({
					mobile: this.phone,
					code: this.code
				}).then(res => {
					uni.$u.toast("验证成功");
					setTimeout(() => {
						// uni.reLaunch({
						// 	url: "/pages/authPage/index?type=" + this.type
						// })
						uni.redirectTo({
							url: "/pages/realNameAuth/index"
						})
					}, 2000)
				})
				console.log('输入结束，当前值为：' + e);
			},
		}
	}
</script>

<style scoped lang="scss">
	page {
		background-color: #F6F6F6;
	}

	.page {
		margin: 20rpx;
	}

	// ::v-deep .u-status-bar {
	// 	height: 80rpx !important;
	// }

	.btn {
		margin: 100rpx 30rpx;
	}

	.tips {
		margin-top: 80rpx;
		margin-left: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 60rpx;
		color: #333333;
		line-height: 84rpx;
	}

	.tips1 {
		margin-top: 10rpx;
		margin-left: 35rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #999999;
		line-height: 40rpx;
	}

	.code {
		margin: 40rpx 20rpx;
		// text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.countdown {
		margin: 40rpx 20rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #333333;
		line-height: 40rpx;
	}

	.bottom-tips {
		width: 100%;
		position: fixed;
		bottom: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 24rpx;
		color: #152A8B;
		line-height: 33rpx;
	}
</style>